package financial.sharing.center.contract.service.impl;

import financial.sharing.center.common.enums.EnableStatusEnum;
import financial.sharing.center.common.enums.ResponseContext;
import financial.sharing.center.contract.dao.ContractDetailMapper;
import financial.sharing.center.contract.feign.InvoiceFeignTestService;
import financial.sharing.center.contract.model.entity.Contract;
import financial.sharing.center.contract.model.entity.ContractDetail;
import financial.sharing.center.contract.model.vo.ContractDetailVO;
import financial.sharing.center.contract.service.ContractDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

/**
 * @ClassName ContractDetailServiceImpl
 * @Description TODO
 * @Author guoyuhang
 * @ @csdn https://blog.csdn.net/qq_40788718
 * @Date 2021/5/11
 * @Version 1.0
 */
@Service
public class ContractDetailServiceImpl implements ContractDetailService {

    @Autowired
    private ContractDetailMapper contractDetailMapper;

    @Override
    public Integer createContractDetail(ContractDetail contractDetail) {
        int i = this.contractDetailMapper.insert(contractDetail);
        return i == 1 ? ResponseContext.成功.getValue() : ResponseContext.创建失败.getValue();
    }

    @Override
    public ContractDetail getOneContractDetail(Contract contract) {
        Example example = new Example(ContractDetail.class);
        example.createCriteria().andEqualTo("contractId",contract.getId())
                .andEqualTo("enableStatusValue", EnableStatusEnum.正常.getValue());
        ContractDetail contractDetail = this.contractDetailMapper.selectOneByExample(example);
        return contractDetail;
    }

    @Override
    public Integer compileOneContractDetail(ContractDetail contractDetail) {
        int i = this.contractDetailMapper.updateByPrimaryKey(contractDetail);
        return i == 1 ? ResponseContext.成功.getValue() : ResponseContext.更新失败.getValue();
    }
}
